<template>
    <!-- 模板部分保持不变 -->
    <v-md-editor v-bind="$attrs" :height="props.height" left-toolbar="undo redo clear | h bold italic strikethrough quote | 
                    ul ol table hr | link image code |  emoji save" :disabled-menus="[]"
        @upload-image="handleUploadImage" @copy-code-success="handleCopyCodeSuccess"></v-md-editor>
</template>

<script setup lang="ts">
import { koiMsgError, koiMsgSuccess } from '@/utils/koi';
import { requestMethod } from '@/utils/upload';
const props = defineProps({
    // 其他属性保持不变
    height: {
        type: String,
        default: '75vh'
    },
});

const handleUploadImage = async (event: Event, insertImage: any, files: File[]) => {
    try {
        // 循环处理多个文件
        for (const file of files) {
            const res = await requestMethod({ file });
            if (res.status === 'success' && res.data?.url) { // 防止undefined
                insertImage({
                    url: res.data.url, // 从data字段获取url
                    desc: '暂无描述'
                });
            } else {
                koiMsgError('图片上传成功但返回格式异常');
            }
        }
        koiMsgSuccess(`成功上传${files.length}张图片`);
    } catch (error) {
        koiMsgError('图片上传失败');
    }
};

// 复制代码回调保持不变
const handleCopyCodeSuccess = (event: Event, text: string) => {
    koiMsgSuccess("已复制到剪贴板");
};
</script>